package excel

import (
	"fmt"
	"strconv"
	"strings"

	"github.com/xuri/excelize/v2"
)

type xlsx struct {
	f            *excelize.File
	active_name  string
	active_index int
	index_name   map[int]string
	name_index   map[string]int
}

// row,col => B3 式坐标，从左上角1,1开始
func rc2cell(rc string) string {
	if strings.Contains(rc, ",") {
		split := strings.Split(rc, ",")
		_row, _col := split[0], split[1]
		row, e := strconv.ParseInt(_col, 10, 64)
		if e != nil {
			return rc
		}

		var ret string
		y := int64(0)
		z := row - 1
		for z >= 0 {
			z, y = z/26, z%26
			ret = fmt.Sprintf("%c%s", y+'A', ret)
			z--
		}

		rc = fmt.Sprintf("%s%s", ret, _row)
	}

	return rc
}
